<?php
require './include/global.php';
require './include/validate.php';
require './include/all_left.php';
require_once './include/advisory_db.php';

$now = time();
$thirtydaysbefore = time() - 86400 * 30;

//messages sent
$sql = "SELECT COUNT(*) AS count FROM pa_email WHERE 1=1 AND e_sentrcid ='".$_SESSION['uid']."' AND e_senderdel= 0 AND e_created > '".$thirtydaysbefore."' AND e_created < '".$now."'";
$result = $DB->fetch_one_array($sql);
$smarty->assign("messagesent",$result['count']);

//messages received
$sql = "SELECT COUNT(*) AS count FROM pa_email WHERE 1=1 AND e_receivedrcid ='".$_SESSION['uid']."' AND e_receiverdel= 0 AND e_created > '".$thirtydaysbefore."' AND e_created < '".$now."'";
$result = $DB->fetch_one_array($sql);
$smarty->assign("messagereceived",$result['count']);

//candidate added
$sql = "SELECT COUNT(*) AS count FROM pa_resume WHERE `re_usertype`='recruiter' AND `re_uid`='".$_SESSION['uid']."' AND re_aliasid = '0' AND re_regtime > '".$thirtydaysbefore."' AND re_regtime < '".$now."'";
$result = $DB->fetch_one_array($sql);
$smarty->assign("candidateadded",$result['count']);

//contact added
$sql = "SELECT COUNT(*) AS count FROM pa_mycontacts WHERE 1=1 AND myc_rcid = '".$_SESSION['uid']."' AND myc_created > '".$thirtydaysbefore."' AND myc_created < '".$now."'";
$result = $DB->fetch_one_array($sql);
$smarty->assign("contactadded",$result['count']);

//group added
$sql = "SELECT COUNT(*) AS count FROM pa_contactgroup WHERE cgp_rcid='".$_SESSION['uid']."' AND cgp_created > '".$thirtydaysbefore."' AND cgp_created < '".$now."'";
$result = $DB->fetch_one_array($sql);
$smarty->assign("groupadded",$result['count']);

//job posted
$sql = "SELECT COUNT(*) AS count FROM  pa_job WHERE `jo_utype`='recruiter' AND `jo_uid`='".$_SESSION['uid']."' AND jo_regtime > '".$thirtydaysbefore."' AND jo_regtime < '".$now."'";
$result = $DB->fetch_one_array($sql);
$smarty->assign("jobposted",$result['count']);

//job approved to work on
$sql = "SELECT SUM(count) FROM (SELECT COUNT(*) AS count FROM pa_job as a ,pa_contact as b WHERE a.jo_id = b.re_aliasid AND b.re_uid = '".$_SESSION['uid']."' AND (`jo_status` <> '3' AND re_isapproved <> 0)  
AND b.re_updtime >  '".$thirtydaysbefore."' AND b.re_updtime < '".$now."'
GROUP BY a.jo_id ) AS t1 ";
$result = $DB->fetch_one_array($sql);
$result['count'] = ($result['SUM(count)']>0)?$result['SUM(count)']:0;
$smarty->assign("jobapproved",$result['count']);


//applicants received
$sql = "SELECT COUNT(*) AS count FROM pa_applicant as a ,pa_resume as b,pa_job as d WHERE d.jo_id = a.app_jobid AND a.app_resumeid = b.re_id AND (a.app_isdelete = 0 OR a.app_isdelete = 2) AND a.app_ownid = '".$_SESSION['uid']."' AND a.app_regtime >  '".$thirtydaysbefore."' AND a.app_regtime < '".$now."' ";
$result = $DB->fetch_one_array($sql);
$smarty->assign("applicantreceived",$result['count']);

//candidate submitted
$sql = "SELECT COUNT(*) as count FROM pa_applicant as a ,pa_resume as b,pa_job as d WHERE d.jo_id = a.app_jobid AND a.app_resumeid = b.re_id AND a.app_recruitid = '".$_SESSION['uid']."' AND a.app_regtime >  '".$thirtydaysbefore."' AND a.app_regtime < '".$now."'";
$result = $DB->fetch_one_array($sql);
$smarty->assign("candidatesubmitted",$result['count']);

$smarty->display('header.tpl');
$smarty->display('allleft.tpl');
$smarty->display('recdashboard.tpl');

$smarty->display('allright.tpl');
$smarty->display('footer.tpl');
?>
